package alex.rsx.reader;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * 
 * @author Alex.Lu
 * 
 */
public class ReaderSet {

	private String PREFS_READER="reader_set";
	private SharedPreferences mSPReader;
	private Editor mSDReader;
	private String PREFS_FONT_SIZE="font_size";
	private String PREFS_FONT_COLOR = "font_color";
	private String PREFS_BRIGHTNESS = "brightness";
	private String PREFS_READMODE = "readmode";
	private String PREFS_READ_BG = "read_bg";
	private String PREFS_READMODEL = "readmodel";
	private String PREFS_FONTFAMILY = "font_family";
	private String PREFS_FONTSTYLE = "font_style";
	
	
	private float mFontSize;
	
	private int mBrightness;
	
	private int mReadBg;
	
	private int mReadmode;
	
	private boolean mReadmodel;
	
	private int mFontColor;
	
	private String mFontFamily;
	
	private int mFontStyle;
	
	
	private static ReaderSet instance;
	
	public static ReaderSet getInstance(){
		if(instance == null)
			instance = new ReaderSet();
		
		return instance;
	}
	
	
	/**
	 * 初始化阅读设置
	 * @param context
	 */
	public void init(Context context){
		mSPReader = context.getSharedPreferences(PREFS_READER, 0); 
		mFontSize = mSPReader.getFloat(PREFS_FONT_SIZE, 18.0f);
		mBrightness = mSPReader.getInt(PREFS_BRIGHTNESS, 255);
		int defaultFontColor = (Integer)ReaderConfig.READBG_MAP.get(0).mValue2;
		mFontColor = mSPReader.getInt(PREFS_FONT_COLOR, defaultFontColor);
		int defaultReadBg = (Integer)ReaderConfig.READBG_MAP.get(0).mValue;
		mReadBg = mSPReader.getInt(PREFS_READ_BG, defaultReadBg);
		mReadmode = mSPReader.getInt(PREFS_READMODE, ReaderConfig.READMODE.get(0).mKey);
		mReadmodel = mSPReader.getBoolean(PREFS_READMODEL, false);
		mFontFamily = mSPReader.getString(PREFS_FONTFAMILY, (String)ReaderConfig.READFAMILY.get(0).mValue);
		mFontStyle = mSPReader.getInt(PREFS_FONTSTYLE, 0);
		
	}
	
	
	public ReaderSet(){
	}
	
	/**
	 * 设置字体大小
	 * @param mFontSize
	 */
	public void decreaseFontSize() {
		this.mFontSize = mFontSize - 2;
	}
	
	/**
	 * 设置字体大小
	 * @param mFontSize
	 */
	public void increaseFontSize() {
		this.mFontSize = mFontSize + 2;
	}
	
	/**
	 * 获取字体大小
	 * @return
	 */
	public float getmFontSize() {
		return mFontSize;
	}
	public void setFontSize(float size){
		mFontSize = size;
	}
	
	/**
	 * 设置阅读背景
	 * @param readBg
	 */
	public void setReadBg(int readBg){
		mReadBg = readBg;
	}
	/**
	 * 获取阅读背景
	 * @return
	 */
	public int getReadBg(){
		return mReadBg;
	}
	/**
	 * 设置阅读的方式
	 * @param readMode
	 */
	public void setReadmode(int readMode){
		mReadmode = readMode;
	}
	
	/**
	 * 获取阅读的方式
	 * @return
	 */
	public int getReadmode(){
		return mReadmode;
	}
	
	/**
	 * 设置亮度
	 * @param brightness
	 */
	public void setBrightness(int brightness){
		mBrightness = brightness;
	}
	
	/**
	 * 设置字体颜色
	 * @param color
	 */
	public void setFontColor(int color){
		mFontColor = color;
	}
	
	/**
	 * 获取字体颜色
	 * @return
	 */
	public int getFontColor(){
		return mFontColor;
	}
	/**
	 * 获取亮度
	 * @return
	 */
	public int getBrightness(){
		return mBrightness;
	}
	
	public void setReadModel(boolean readModel){
		mReadmodel = readModel;
	}
	
	public boolean getReadModel(){
		return mReadmodel;
	}
	
	/**
	 * 设置字体
	 * @param family
	 */
	public void setFontFamily(String family){
		mFontFamily = family;
	}
	
	/**
	 * 获取字体
	 * @return
	 */
	public String getFontFamily(){
		return mFontFamily;
	}
	
	/**
	 * 设置字体类型
	 * @param style
	 */
	public void setFontStyle(int style){
		mFontStyle = style;
	}
	
	/**
	 * 获取字体类型
	 * @return
	 */
	public int getFontStyle(){
		return mFontStyle;
	}
	
	/**
	 * 提交阅读设置
	 */
	public void commitReaderSet(){
		mSDReader = mSPReader.edit();
		mSDReader.putFloat(PREFS_FONT_SIZE, mFontSize);
		mSDReader.putInt(PREFS_BRIGHTNESS, mBrightness);
		mSDReader.putInt(PREFS_READ_BG, mReadBg);
		mSDReader.putInt(PREFS_FONT_COLOR, mFontColor);
		mSDReader.putInt(PREFS_READMODE, mReadmode);
		mSDReader.putString(PREFS_FONTFAMILY, mFontFamily);
		mSDReader.putInt(PREFS_FONTSTYLE, mFontStyle);
		mSDReader.putBoolean(PREFS_READMODEL, mReadmodel);
		mSDReader.commit();
	}
	
}
